The present invention relates to a method for determining the threshold of an image so as to automatically measure or inspect an industrial product utilizing image information.
In an image process for measuring the position of an object or inspecting the configuration thereof, it is necessary to separate a region corresponding to the object from the background thereof according to the image information. To this end, the following methods are carried out. First, a reference lightness (i.e. light intensity level) value, namely, a binarization threshold is determined. An image is divided into two portions depending on the lightness value thereof. That is, one portion (a bright portion) has a lightness value higher than the reference lightness value and the other portion (a dark portion) has a lightness value smaller than the reference lightness value. The bright portion and the dark portion are selected as the region of the object according to the reflectivities of the object and the background. According to this method, the lightness values of the image are converted into two values of zero and one, namely, the lightness values are binarized.
If a plurality of objects are to be measured or if the lightness value of the background is not uniform (i.e., if the background has a portion having a lightness value greater than that of the object and a portion having a lightness value smaller than that of the object), a plurality of reference lightness values are set to carry out, for example, ternarization of the lightness values of the image. The reference lightness value is called a multivalue threshold, for example, a ternarization threshold. It is necessary to determine the multivalue threshold, for example, the ternarization threshold, depending on an image condition which is varied by the fluctuations of illuminance and reflectivity of the object.
Two examples of conventional methods for determining a binarization threshold are described in detail below, while a method for determining a multivalue threshold is only briefly described (since the method for determining the multivalue threshold can be easily realized by expanding the method for determining the binarization threshold and has the same general characteristics as the method for determining the binarization threshold).
The first conventional method is described with reference to FIG. 6 and FIG. 9.
FIG. 6 is an illustration showing the entire structure of an image processing apparatus according to the first conventional method. The image of an object 5 is inputted to a television camera 7 through a lens 6. Upon receipt of a light image from the object 5, a photoelectric conversion circuit provided in the television camera 7 functions. An electric signal generated by the photoelectric conversion circuit is converted into digital value image data by an analog-digital conversion circuit 8. The image data is stored by an image storing circuit 9.
A central processing unit 10 processes the image data stored by the image storing circuit 9 as follows: A binarization threshold is determined so that the ratio of the area of a bright portion (having lightness values exceeding the binarization threshold) to the area of the entire image is equal to a preset binarization threshold determining ratio of the bright portion.
The binarization threshold determining ratio of the bright portion is normally determined as follows: First, a sample object having an acceptable reflectivity and configuration is selected. The sample object is hereinafter referred to as a reference object. FIG. 7 shows the image of a reference object 12 against a background 11. Binarization of the image lightness values of the image shown in FIG. 7 are repeatedly performed based on various binarization thresholds so as to determined by human judgement the most appropriate binarization threshold for measuring the position of the reference object 12 and inspecting the configuration thereof. Calculations are then performed to obtain the ratio of the area of a bright portion (having lightness values greater than the thus determined binarization threshold) to the area of the entire image. The above ratio is set as the binarization threshold determining ratio of the bright portion.
A characteristic of this method is that the binarization threshold varies greatly depending on the size of the reference object. The reason for this is described below.
FIG. 8 is a lightness histogram of an image. The abscissa axis denotes lightness values and the ordinate axis denotes a frequency of measured light values. The solid line 13 is the lightness histogram of the reference object 12 (the image shown in FIG. 7), and the dashed line 14 shows the level of the binarization threshold determined as most appropriate for measuring the position of the reference object 12 and inspecting the configuration thereof. The determination of a binarization threshold according to this method on an object other than the reference object 12 of FIG. 7 is described below. Suppose that the object is larger than the reference object 12. As shown by the lightness histogram 15 in FIG. 8, compared with the lightness histogram 13 of the reference object 12, the frequency of lightness values exceeding the threshold 14 increases. That is, the image of the object has a larger bright portion than that of the reference object 12. Consequently, the level of the binarization threshold of the image calculated based on the binarization threshold determining ratio of the bright portion increases as shown by the one-dot line 16 in FIG. 8, thus being greater than the binarization threshold 14 set as described above. Performing a binarization process based on this binarization threshold, the edge of the image looks unclear or thin as shown in FIG. 9. As such, the measurement of the position of an industrial product and the inspection of the configuration thereof cannot be appropriately carried out.
The situation described above occurs in the image processing of an object which is larger than the reference object. A similar situation occurs in the image processing of an object which is smaller than the reference object in which the configuration of the edge of the image also appears unclear or blurry. As with the larger object, the measurement of the position of a smaller object and the inspection of the configuration thereof cannot be appropriately carried out.
As is apparent from the above, according to the first conventional method, the appropriateness of the binarization threshold depends on the size of a measured object. That is, with an increase or decrease in the size of the object, the region or the edge corresponding to the object cannot be correctly processed in such a manner that the image of the object is distinguished from the background.
In order to expand the above method for determining the binarization threshold into a method for determining a multivalue threshold, two or more thresholds are repeatedly set according to respective multivalue threshold determining ratios of the bright portion. Such a method for determining the multivalue threshold has the same characteristics as discussed above with respect to the method for determining the binarization threshold.
Referring to FIG. 10 through FIG. 12, a second conventional method will be described below. The entire structure of an image processing apparatus according to the second conventional method is similar to that of the image processing apparatus according to the first conventional method shown in FIG. 6. The method for processing an image by the central processing unit according to the second conventional method is described below.
As shown in the lightness histogram of FIG. 10, a portion 17 corresponds to a background image and has a large frequency of lightness values which are smaller than a binarization threshold (which is described below), and a portion 18 corresponds to an object image and has a relatively small frequency of lightness values which are greater than the binarization threshold. A lightness value 19 at which the frequency lightness values is minimum between the two portions 17 and 18 is set as the binarization threshold.
A characteristic of the second conventional method is that there is a large fluctuation of the lightness values at the minimum frequency point. When the brightness of an object is significantly different from that of the background, the portion of the histogram at which the frequency is small fluctuates greatly in a wide range due to the fluctuation of an electric signal. That is, the lightness values of the image of an object in the minimum frequency point of the histogram fluctuate greatly in a wide range. The frequency of the lightness values becomes smallest at the lightness value 19 shown in the histogram of FIG. 10, while the frequency of lightness values becomes smallest at a lightness value represented by the dashed line 20 shown in the histogram of FIG. 11 in which the lightness distribution differs a little from that shown in FIG. 10. The lightness value 20 is much greater than the lightness value 19. In order to prevent the lightness values from fluctuating too much, the histogram may be smoothed, i.e., the histogram frequencies may be averaged in a certain range. However, depending on the object, the configuration of a smoothed histogram can differ significantly from that of the original histogram, and the lightness value at the minimum histogram frequency can thus become inappropriate for serving as a binarization threshold. For example, referring to FIG. 12, reference numeral 21 denotes a histogram of an image and reference numeral 22 designates a smoothed histogram obtained by smoothing the histogram 21. As shown, the configurations and the minimum values thereof clearly differ from each other.
As is apparent from the above description, according to the second conventional method, the calculated binarization threshold can be inappropriate due to influences, such as the fluctuations of electric signals, depending on the object measured. Therefore, the object or the edge of a region corresponding to the object cannot be appropriately distinguished from the background. No effective means to prevent this disadvantage has been found.
The determination of the binarization threshold according to the second conventional method may be expanded into a method for determining a multivalue threshold as follows: According to a method for determining the multivalue threshold, the lightness value distribution takes the form of three portions or more having valleys therebetween. Therefore, the minimum frequency point of each of the plurality of valleys is detected as a threshold. Such a method for determining the multivalue threshold has the same characteristics as those discussed above with respect to the method for determining the binarization threshold.
As described above, according to the conventional methods, depending on the object, an appropriate binarization threshold or multivalue thresholds cannot be obtained due to influences such as fluctuations of electric signals. Therefore, the object or the edge of a region corresponding to the object cannot be clearly distinguished from the background of the object.